package com.banmao.algorithm.No1To100.No5_Longest_Palindromic_Substring;

/**
 *  暴力破解
 */
class Solution01 {
    static String longestPalindrome(String s) {
        int len = s.length();
        if(len<2){
            return s;
        }
        int maxLen = 1;
        int begin = 0;
        char[] list = s.toCharArray();
        for(int i=0; i<len;i++){
            for(int j=i+1; j<len; j++){
                if(j-i+1>maxLen && judge(list, i, j)){
                    maxLen = j-i+1;
                    begin = i;
                }
            }
        }
        return s.substring(begin, begin+maxLen);
    }

    private static boolean judge(char[] list, int left, int right) {
        while(left < right){
            if(list[left] != list[right]){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
